/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package e.odbo.data.dao;

import com.openbravo.data.basic.BasicException;
import e.odbo.data.dsl.query.QBFParameters;
import e.odbo.data.bean.IKeyed;
import e.odbo.data.dsl.operation.QueryOperation;

import java.util.List;

/**
 * @author Administrator
 */
public abstract class InfoDAO<T extends IKeyed, V extends BaseDAO> extends ViewDAO<T> {
    protected int[] columnIndexs;
    protected V base;

    public InfoDAO(V base) {
        this(base, base.getTableBuilderWarp().getTable().getAllFields());
    }


    public InfoDAO(EntityManager entityManager,V base,int[] columnIndexs){
        this(base,columnIndexs);
        entityManager.addDaoToMap(this);
    }

    public InfoDAO(V base, int[] columnIndexs) {
        super(base.s);
        this.base = base;
        this.columnIndexs = columnIndexs;
    }

    @Override
    public List<T> list() throws BasicException {
        return base.getTableBuilderWarp().getListSentence(this,columnIndexs).list();
    }

    public T find(IKeyed f) throws BasicException {
        return (T)base.getTableBuilderWarp().getFindSentence(this,base.getKeySerializerWrite(),columnIndexs).find(f);
    }

    @Override
    public List<T> list(QueryOperation queryOperation) throws BasicException {
        return base.getTableBuilderWarp().getListSentence(this,columnIndexs,queryOperation).list();
    }

    @Override
    public List<T> query(QBFParameters filter) throws BasicException {
        return base.getTableBuilderWarp().getQuerySentence(this,columnIndexs,filter).list(filter);
    }

    @Override
    public List<T> query(QBFParameters filter, QueryOperation queryOperation) throws BasicException {
        return base.getTableBuilderWarp().getQuerySentence(this,columnIndexs,filter,queryOperation).list(filter);
    }

}
